package com.nbgroup.aspect;

import com.nbgroup.mapper.OperlogMapper;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Collections;

@Slf4j
@Aspect
@Component
public class AutoLogAspect {

    @Pointcut("execution(* com.nbgroup.controller.*.*(..))")
    private void pointCut(){}


    /**
     * 自动为Controller添加日志
     * @param joinPoint
     */
    @Before("pointCut()")
    public void autoLog(JoinPoint joinPoint){
        log.info("代理方法开始时执行,为控制层记录日志");
        Object[] args = joinPoint.getArgs();
        if (args != null){
            for (int i = 0; i < args.length; i++) {
                log.info("接收到的第"+(i+1)+"个参数为:{}",args[i]);
            }
        }

    }
}
